from flask import Flask, jsonify, request, send_file
import requests
import json
import execelUtil.common.commonUtil as comutl
import execelUtil.common.commonConstants as ct
import execelUtil.json2excel as json2excel
from PIL import Image
import base64
import io
import execelUtil.checkData.checkPurProduceTransit as ckpur

from flask_cors import CORS

# 创建Flask应用实例
app = Flask(__name__)
CORS(app)


# 定义路由和视图函数
@app.route("/hello", methods=["GET"])
def hello():
    return jsonify({"message": "Hello, world!"})


@app.route("/tms/tc", methods=['GET', 'POST'])
def getTcData():
    r = request.args.get('info', 'hi')
    print(r)
    url = ct.HEAD_LIST_URL
    body = comutl.getApiList(ct.HEAD_LIST_PARA_BODY)
    body["shipmentPlanId"] = r
    bill_list = comutl.getBillLists(url, body, [])
    return jsonify(bill_list)


@app.route("/tms/tcDetail", methods=['GET', 'POST'])
def getTcDetailData():
    r = request.args.get('info', 'hi')
    print(r)
    url = comutl.getApiList(ct.HEAD_DETAIL_URL)
    print(url)
    params = {"shipmentPlanId": r}
    # params = json.dumps(params)
    response = requests.get(url, params=params, headers=comutl.getHeaders())
    print(response.text)
    return response.text


@app.route("/wms/invstore", methods=['GET', 'POST'])
def getWmsStorageInv():
    params = request.get_json()
    # skuCode = request.args.get('skuCode', 'hi')
    # whCode = request.args.get('whCode', 'hi')
    skuCode = params[ct.SKUCODE]
    print(params)
    url = ct.WMS_STORAGE_INV_URL
    # params = comutl.getApiList(comutl.WMS_STORAGE_INV_PARA_BODY)
    # print(url)
    # params = json.dumps(params)
    # params = json.dumps(params)
    # print(params)
    bill_list = comutl.getBillLists(url, params, [])
    # response = requests.post(url, params=params, headers=comutl.getHeaders())
    all_bill = comutl.getBillListswithall(url, params, [])
    bill_res = []
    sum_inv = 0;
    if len(all_bill) > 0:
        for i in range(len(all_bill)):
            if "invQty" in all_bill[i] and all_bill[i]["invQty"] > 0:
                sum_inv += int(all_bill[i]["invQty"])
    print(skuCode, sum_inv)
    return bill_list


@app.route("/wms/warehouseInfo", methods=['GET', 'POST'])
def getWmsWarehouseInfo():
    params = request.get_json()
    # skuCode = request.args.get('skuCode', 'hi')
    # whCode = request.args.get('whCode', 'hi')
    skuCode = params[ct.SKUCODE]
    print(params)
    url = ct.WMS_STORAGE_INV_URL
    # params = comutl.getApiList(comutl.WMS_STORAGE_INV_PARA_BODY)
    # print(url)
    # params = json.dumps(params)
    # params = json.dumps(params)
    # print(params)
    bill_res = []
    bill_list = comutl.getBillLists(url, params, [])
    # response = requests.post(url, params=params, headers=comutl.getHeaders())
    all_bill = comutl.getBillListswithall(url, params, [])
    sum_inv = 0
    if len(all_bill) > 0:
        for i in range(len(all_bill)):
            if "invQty" in all_bill[i] and all_bill[i]["invQty"] > 0:
                sum_inv += int(all_bill[i]["invQty"])

    sum_bill_inv = 0
    if len(bill_list) > 0:
        bill_list[0]["totalQty"] = sum_inv

    print(skuCode, sum_inv)
    return bill_list


@app.route("/inv/billOccupy", methods=['GET', 'POST'])
def getInvBillOccpy():
    params = request.get_json()
    if params["bizType"] is None or params["bizType"] == '':
        params["bizTypeList"] = comutl.GOOD_HOLD_BIZ_TYPE
    elif params["bizType"] == "all":
        params["bizTypeList"] = comutl.BIZ_TYPE
    else:
        params["bizTypeList"] = []
        params["bizTypeList"].append(params["bizType"])
    print(params)
    bill_list = comutl.getOccpyBySku(params)
    print(params)
    return bill_list


@app.route("/tms/headtransitDetail", methods=['GET', 'POST'])
def getHeadtransitDetail():
    params = request.get_json()
    print(params)
    paras = comutl.getApiList(ct.HEAD_DETAIL_PARA_BODY)
    if "skuCode" in params and params["skuCode"] is not None:
        paras["cInvCode"] = params["skuCode"]
    paras[ct.HEAD_DETAIL_PARA_BODY_SHIPMENTPLANID] = params["shipNo"]
    resp = comutl.getBillListsWithGet(ct.HEAD_DETAIL_URL, paras)
    print(resp)
    return resp


@app.route("/inv/getOrderErrorLog", methods=['GET', 'POST'])
def getOrderErrorLog():
    params = request.get_json()
    print(params)
    paras = comutl.getApiList(ct.HEAD_DETAIL_PARA_BODY)
    if "skuCode" in params and params["skuCode"] is not None:
        paras["cInvCode"] = params["skuCode"]
    paras[ct.HEAD_DETAIL_PARA_BODY_SHIPMENTPLANID] = params["shipNo"]
    resp = comutl.getBillListsWithGet(ct.HEAD_DETAIL_URL, paras)
    print(resp)
    return resp


@app.route("/purchase/purchasetransitDetail", methods=['GET', 'POST'])
def getPurchasetransitDetail():
    params = request.get_json()
    print(params)
    paras = comutl.getApiList(ct.HEAD_DETAIL_PARA_BODY)
    if "skuCode" in params and params["skuCode"] is not None:
        paras["cInvCode"] = params["skuCode"]
    paras[ct.HEAD_DETAIL_PARA_BODY_SHIPMENTPLANID] = params["shipNo"]
    resp = comutl.getBillListsWithGet(ct.HEAD_DETAIL_URL, paras)
    print(resp)
    return resp


@app.route('/img/recognition', methods=['POST'])
def send_img():
    # print(request.args)
    # print(request.form)
    # print(request.files)
    print(request.files)
    f = request.files['file']
    print(f)
    img = f.read()
    print('img', type(img))
    byte_stream = io.BytesIO(img)
    # im2 = Image.open(byte_stream)
    # print('im2',type(im2))
    encoded_string = base64.b64encode(byte_stream.getvalue())
    print(encoded_string.decode("utf-8"))
    req_exam = dict()
    req_exam["image"] = encoded_string.decode("utf-8")
    print('image',req_exam)
    result = requests.post("http://hwnode2:5005/ocr", json=req_exam)
    print(result.text)
    res_result = json.loads(result.text)
    str_result = ""
    if result is not None and "results" in res_result:
        result_list = res_result["results"]
        print(result_list)
        for i in range(len(result_list)):
            print(result_list[i])
            str_result = str_result + "\n" + result_list[i]['text']
    # img_cv2 = cv2.imdecode(np.frombuffer(img, np.uint8), cv2.IMREAD_COLOR)
    # im1 = Image.fromarray(img_cv2)
    # print('im1',type(im1))
    # import io
    # byte_stream = io.BytesIO(img)
    # im2 = Image.open(byte_stream)
    # print('im2',type(im2))
    # result = orcmy.get_text_from_pic(img_cv2)
    res_data = dict()
    res_data["data"] = str_result
    res_data["code"] = 200
    res_data ["msg"] = "成功"
    return res_data


def image_to_base64(file_path):
    image = Image.open(file_path)
    byte_stream = io.BytesIO()
    image.save(byte_stream, format="PNG")  # 可根据需要修改保存格式
    encoded_string = base64.b64encode(byte_stream.getvalue())
    return encoded_string.decode("utf-8")


@app.route('/inv/generateBillData', methods=['POST'])
def generateBillData():
    # print(request.args)
    # print(request.form)
    # print(request.files)

    result = ""
    return result


@app.route('/inv/getPurTransitAndInvOcc', methods=['POST'])
def getPurTransitAndInvOcc():
    params = request.get_json()
    print(params)
    result_list = ckpur.checkPurTrasitQty(params["skuCode"],params["size"])
    res_data = dict()
    res_data["data"] = result_list
    res_data["code"] = 200
    res_data["msg"] = "成功"
    return res_data



@app.route('/inv/getpurWithsuplr', methods=['POST'])
def getpurWithsuplr():
    params = request.get_json()
    print(params)
    result = ckpur.checkPurTrasitQtyWithSuplr(params["skuCode"])
    res_data = dict()
    res_data["data"] = result
    res_data["code"] = 200
    res_data["msg"] = "成功"
    return res_data


@app.route('/isaccountexists', methods=['GET'])
def checkAccount():
    print(request.headers)
    # print(request.stream.read()) # 不要用，否则下面的form取不到数据
    # print(request.form)
    # print(request.form['name'])
    # print(request.form.get('name'))
    # print(request.form.getlist('name'))
    # print(request.form.get('nickname', default='little apple'))
    data = {}
    rep = {}

    rep["code"] = "200"
    rep['data'] = True
    rep["msg"] = data
    return rep


@app.route('/istelephoneexists', methods=['GET'])
def checkTelephone():
    print(request.headers)
    # print(request.stream.read()) # 不要用，否则下面的form取不到数据
    # print(request.form)
    # print(request.form['name'])
    # print(request.form.get('name'))
    # print(request.form.getlist('name'))
    # print(request.form.get('nickname', default='little apple'))
    data = {}
    rep = {}

    rep["code"] = "200"
    rep['data'] = True
    rep["msg"] = data
    return rep


@app.route('/login', methods=['POST'])
def login():
    print(request.headers)
    # print(request.stream.read()) # 不要用，否则下面的form取不到数据
    # print(request.form)
    # print(request.form['name'])
    # print(request.form.get('name'))
    # print(request.form.getlist('name'))
    # print(request.form.get('nickname', default='little apple'))
    rep = {}
    rep["code"] = 200
    rep["data"] = "wvNH/20uaaBpBlU7h4Foxw=="
    rep["msg"] = "登录成功"
    return rep


@app.route('/api/login', methods=['POST', 'GET'])
def ailogin():
    body = dict()
    body = {
        "code": 200,
        "msg": "成功",
        "data": {
            "accessToken": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjE4IiwiaWF0IjoxNzI5MTM0NjA0LCJleHAiOjE3MjkxMzgyMDR9.dtR6jl73nti52uvgTpUkF826S3nvAMh1_l64edXT8Xs",
            "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjE4IiwiaWF0IjoxNzI5MTM0NjA0LCJleHAiOjE3Mjk3Mzk0MDR9.03yXaIv0ofj-ugJSwpL39wQZvO7mfrEE6WMiZ8TkVMo"
        }
    }
    return body


@app.route('/inv/getWhList', methods=['POST', 'GET'])
def getWhList():
    print(request.headers)
    params = request.get_json()
    Flag = True
    for prop in params:
        if params[prop] is not None or params[prop] != '':
            Flag = False
            break
    if Flag:
        params = None

    # print(request.stream.read()) # 不要用，否则下面的form取不到数据
    # print(request.form)
    # print(request.form['name'])
    # print(request.form.get('name'))
    # print(request.form.getlist('name'))
    # print(request.form.get('nickname', default='little apple'))
    rep = comutl.getwarehouse_list(params)
    return rep


@app.route('/api/perm/menu', methods=['POST', 'GET'])
def aigetp_menu():
    body = dict()
    body = {
        "code": 200,
        "msg": "ok",
        "data": [
            {
                "id": "1",
                "name": "首页",
                "code": "dashboard",
                "type": 1,
                "parentId": "0",
                "orderNum": 0
            },
            {
                "id": "33",
                "name": "视频营销",
                "code": "videoMa",
                "type": 1,
                "parentId": "0",
                "orderNum": 0
            },
            {
                "id": "40",
                "name": "视频生成",
                "code": "videoMa:gen",
                "type": 1,
                "parentId": "33",
                "orderNum": 0
            },
            {
                "id": "41",
                "name": "视频编辑",
                "code": "videoMa:pub",
                "type": 1,
                "parentId": "33",
                "orderNum": 0
            },
            {
                "id": "42",
                "name": "视频翻译",
                "code": "videoMa:translate",
                "type": 1,
                "parentId": "33",
                "orderNum": 0
            },
            {
                "id": "43",
                "name": "视频发布新增",
                "code": "videoPub:add",
                "type": 3,
                "parentId": "41",
                "orderNum": 0
            },
            {
                "id": "44",
                "name": "视频发布编辑",
                "code": "videoPub:edit",
                "type": 3,
                "parentId": "41",
                "orderNum": 0
            },
            {
                "id": "45",
                "name": "视频发布删除",
                "code": "videoPub:delete",
                "type": 3,
                "parentId": "41",
                "orderNum": 0
            },
            {
                "id": "46",
                "name": "文件上传",
                "code": "baseAssets",
                "type": 1,
                "parentId": "61",
                "orderNum": 0
            },
            {
                "id": "47",
                "name": "新增资料",
                "code": "baseAssets:add",
                "type": 3,
                "parentId": "46",
                "orderNum": 0
            },
            {
                "id": "48",
                "name": "编辑资料",
                "code": "baseAssets:edit",
                "type": 3,
                "parentId": "46",
                "orderNum": 0
            },
            {
                "id": "49",
                "name": "删除资料",
                "code": "baseAssets:del",
                "type": 3,
                "parentId": "46",
                "orderNum": 0
            },
            {
                "id": "50",
                "name": "视频生成添加",
                "code": "videoGen:add",
                "type": 3,
                "parentId": "40",
                "orderNum": 0
            },
            {
                "id": "51",
                "name": "视频生成修改",
                "code": "videoGen:edit",
                "type": 3,
                "parentId": "40",
                "orderNum": 0
            },
            {
                "id": "52",
                "name": "视频生成删除",
                "code": "videoGen:del",
                "type": 3,
                "parentId": "40",
                "orderNum": 0
            },
            {
                "id": "53",
                "name": "市场机会",
                "code": "customer",
                "type": 1,
                "parentId": "0",
                "orderNum": 0
            },
            {
                "id": "54",
                "name": "机会发现",
                "code": "customerSearch",
                "type": 1,
                "parentId": "53",
                "orderNum": 0
            },
            {
                "id": "55",
                "name": "新增视频翻译",
                "code": "translate:add",
                "type": 3,
                "parentId": "42",
                "orderNum": 0
            },
            {
                "id": "56",
                "name": "视频翻译修改",
                "code": "translate:edit",
                "type": 3,
                "parentId": "42",
                "orderNum": 0
            },
            {
                "id": "57",
                "name": "视频翻译删除",
                "code": "translate:del",
                "type": 3,
                "parentId": "42",
                "orderNum": 0
            },
            {
                "id": "58",
                "name": "竞对研究新增",
                "code": "search:add",
                "type": 3,
                "parentId": "54",
                "orderNum": 0
            },
            {
                "id": "59",
                "name": "竞对研究修改",
                "code": "search:edit",
                "type": 3,
                "parentId": "54",
                "orderNum": 0
            },
            {
                "id": "60",
                "name": "竞对研究删除",
                "code": "search:del",
                "type": 3,
                "parentId": "54",
                "orderNum": 0
            },
            {
                "id": "61",
                "name": "营销资源",
                "code": "assetsPool",
                "type": 1,
                "parentId": "0",
                "orderNum": 0
            },
            {
                "id": "62",
                "name": "数字人",
                "code": "videoMa:actor",
                "type": 1,
                "parentId": "79",
                "orderNum": 0
            },
            {
                "id": "63",
                "name": "发布代理",
                "code": "videoMa:pubMa",
                "type": 1,
                "parentId": "79",
                "orderNum": 0
            },
            {
                "id": "64",
                "name": "视频发布",
                "code": "video:pubStatus",
                "type": 1,
                "parentId": "33",
                "orderNum": 0
            },
            {
                "id": "65",
                "name": "定时发布",
                "code": "videoMa:taskMa",
                "type": 1,
                "parentId": "79",
                "orderNum": 0
            },
            {
                "id": "66",
                "name": "数字人添加",
                "code": "actor:add",
                "type": 3,
                "parentId": "62",
                "orderNum": 0
            },
            {
                "id": "67",
                "name": "数字人修改",
                "code": "actor:edit",
                "type": 3,
                "parentId": "62",
                "orderNum": 0
            },
            {
                "id": "68",
                "name": "数字人删除",
                "code": "actor:del",
                "type": 3,
                "parentId": "62",
                "orderNum": 0
            },
            {
                "id": "69",
                "name": "视频发布配置添加",
                "code": "agent:add",
                "type": 3,
                "parentId": "63",
                "orderNum": 0
            },
            {
                "id": "70",
                "name": "视频发布配置修改",
                "code": "agent:edit",
                "type": 3,
                "parentId": "63",
                "orderNum": 0
            },
            {
                "id": "71",
                "name": "视频发布配置删除",
                "code": "agent:del",
                "type": 3,
                "parentId": "63",
                "orderNum": 0
            },
            {
                "id": "72",
                "name": "视频发布修改",
                "code": "pubsubtask:edit",
                "type": 3,
                "parentId": "64",
                "orderNum": 0
            },
            {
                "id": "73",
                "name": "视频发布删除",
                "code": "pubsubtask:del",
                "type": 3,
                "parentId": "64",
                "orderNum": 0
            },
            {
                "id": "74",
                "name": "视频发布扫码",
                "code": "pubsubtask:qr",
                "type": 3,
                "parentId": "64",
                "orderNum": 0
            },
            {
                "id": "75",
                "name": "定时发布新增",
                "code": "task:add",
                "type": 3,
                "parentId": "65",
                "orderNum": 0
            },
            {
                "id": "76",
                "name": "定时发布修改",
                "code": "task:edit",
                "type": 3,
                "parentId": "65",
                "orderNum": 0
            },
            {
                "id": "77",
                "name": "定时发布删除",
                "code": "task:del",
                "type": 3,
                "parentId": "65",
                "orderNum": 0
            },
            {
                "id": "78",
                "name": "系统配置",
                "code": "sysVideoMa",
                "type": 1,
                "parentId": "0",
                "orderNum": 0
            },
            {
                "id": "79",
                "name": "视频配置",
                "code": "videoSetting",
                "type": 1,
                "parentId": "78",
                "orderNum": 0
            },
            {
                "id": "80",
                "name": "销售外拓",
                "code": "outreach",
                "type": 1,
                "parentId": "0",
                "orderNum": 0
            },
            {
                "id": "81",
                "name": "外拓任务",
                "code": "outreachTask",
                "type": 1,
                "parentId": "80",
                "orderNum": 0
            },
            {
                "id": "82",
                "name": "外拓任务结果",
                "code": "outreachTaskRes",
                "type": 1,
                "parentId": "80",
                "orderNum": 0
            },
            {
                "id": "83",
                "name": "机会发现结果",
                "code": "customerSearchResults",
                "type": 1,
                "parentId": "53",
                "orderNum": 0
            },
            {
                "id": "84",
                "name": "外拓任务新增",
                "code": "outreachTask:add",
                "type": 3,
                "parentId": "81",
                "orderNum": 0
            },
            {
                "id": "85",
                "name": "外拓任务修改",
                "code": "outreachTask:edit",
                "type": 3,
                "parentId": "81",
                "orderNum": 0
            },
            {
                "id": "86",
                "name": "外拓任务删除",
                "code": "outreachTask:del",
                "type": 3,
                "parentId": "81",
                "orderNum": 0
            },
            {
                "id": "87",
                "name": "修改视频url",
                "code": "video:changeUrl",
                "type": 3,
                "parentId": "41",
                "orderNum": 0
            },
            {
                "id": "88",
                "name": "素材管理",
                "code": "materialFile:ma",
                "type": 1,
                "parentId": "41",
                "orderNum": 0
            },
            {
                "id": "89",
                "name": "上传素材",
                "code": "materialFile:add",
                "type": 3,
                "parentId": "88",
                "orderNum": 0
            },
            {
                "id": "90",
                "name": "生成ai素材",
                "code": "materialFile:ai-gen",
                "type": 3,
                "parentId": "88",
                "orderNum": 0
            },
            {
                "id": "91",
                "name": "ai生成素材重试",
                "code": "materiaFile:refresh",
                "type": 3,
                "parentId": "88",
                "orderNum": 0
            },
            {
                "id": "92",
                "name": "素材删除",
                "code": "materialFile:del",
                "type": 3,
                "parentId": "88",
                "orderNum": 0
            },
            {
                "id": "94",
                "name": "ai助手",
                "code": "ai:assistant",
                "type": 3,
                "parentId": "1",
                "orderNum": 0
            },
            {
                "id": "95",
                "name": "修改定时发布状态",
                "code": "task:status",
                "type": 3,
                "parentId": "65",
                "orderNum": 0
            }
        ]
    }
    return body


@app.route('/api/video/list', methods=['POST', 'GET'])
def veditmain():
    resp_Data = {
        "code": 200,
        "msg": "ok",
        "data": {
            "id": 6552,
            "tId": "18",
            "title": "test",
            "videoTitle": "",
            "content": "",
            "code": "\"\"",
            "catalog": " : : :",
            "keywords": "",
            "coverUrl": "",
            "videoUrl": "",
            "videoChange": "",
            "videoType": "douyin",
            "videoActor": "",
            "courseId": 1,
            "courseName": "日常发布",
            "orderInCourse": 0,
            "pubStatus": "-1-问题输入",
            "pubData": "{\"isoriginal\":\"转载\"}",
            "extra": None,
            "createDate": "2024-10-22T11:07:28.000Z",
            "updateDate": "2024-10-22T11:07:28.000Z",
            "language": "zh-CN",
            "isDeleted": 0,
            "accountName": "默认数字人-小火_20241013_201430"
        }
    }
    return resp_Data


@app.route('/api/video-gen-template/list', methods=['POST', 'GET'])
def vedittemplate():
    print(request.headers)
    # print(request.stream.read()) # 不要用，否则下面的form取不到数据
    # print(request.form)
    # print(request.form['name'])
    # print(request.form.get('name'))
    # print(request.form.getlist('name'))
    # print(request.form.get('nickname', default='little apple'))

    resp_data = dict()
    resp_data["id"] = 1
    resp_data["pId"] = "1"
    resp_data["account"] = "admin"
    resp_data["status"] = 1
    resp_data["type"] = 0

    rep = {
        "code": 200,
        "msg": "ok",
        "data": [
            {
                "id": "14",
                "materialType": "1",
                "genTemplateName": "flux",
                "genTemplate": "{\"meterial_type\":\"1\",\"backurl\":\"https://aiapi.supersale.ai/image/sd\",\"timeout\":\"120\",\"auth\":\"admin:Ai_Service_2022\",\"inputs\":[{\"lable\":\"模型类型\",\"id\":\"type\",\"desc\":\"模型类型\",\"type\":\"select\",\"value\":[{\"FLUX-schnell\":\"flux-schnell\",\"FLUX-dev\":\"flux-dev\"}],\"value_type\":\"string\",\"required\":\"true\"},{\"lable\":\"提示词\",\"desc\":\"绘画提示词\",\"id\":\"prompt\",\"type\":\"text\",\"value\":\"a dog fly in the sky\",\"value_type\":\"string\",\"required\":\"true\"},{\"lable\":\"负面提示词\",\"desc\":\"绘画负面提示词\",\"id\":\"negative_prompt\",\"type\":\"text\",\"value\":\"ugly\",\"value_type\":\"string\",\"required\":\"true\"},{\"lable\":\"宽高比\",\"desc\":\"宽高比\",\"id\":\"aspect_ratio\",\"type\":\"text\",\"value\":\"9:16\",\"value_type\":\"string\",\"required\":\"true\"},{\"lable\":\"随机率\",\"desc\":\"随机率\",\"id\":\"random_seed\",\"type\":\"slider\",\"value\":\"12:1.5:12.5\",\"value_type\":\"slider\",\"required\":\"false\"},{\"lable\":\"图片\",\"id\":\"pic_path\",\"desc\":\"本地图片\",\"type\":\"file\",\"value_type\":\"file\",\"required\":\"false\"},{\"lable\":\"是否高清\",\"desc\":\"是否高清\",\"id\":\"is_highresolution\",\"type\":\"checkbox\",\"value\":\"true\",\"value_type\":\"boolean\",\"required\":\"false\"}]}",
                "isDeleted": 0,
                "createTime": "2024-08-28T09:27:22.000Z",
                "updateTime": "2024-08-28T09:27:22.000Z",
                "tId": "1",
                "isPublic": 1
            }
        ]
    }
    return rep


@app.route('/api/video-material-file/list', methods=['POST', 'GET'])
def veditmaterialfile():
    print(request.headers)
    materialType = request.args.get("materialType")
    return {"code": 200, "msg": "ok", "data": {"list": [], "total": 0}}
    # if materialType == 2:
    #     # 要上传的视频文件路径
    #     file_path = '20241021_theme.mp4'
    #     return send_file(file_path)
    #     # 上传的服务器URL
    #     # upload_url = 'http://example.com/upload'
    #     #
    #     # # 使用files参数上传文件
    #     # files = {'video': open(file_path, 'rb')}
    #     # response = requests.post(upload_url, files=files)

    parmas = request.get_json()
    # print(request.stream.read()) # 不要用，否则下面的form取不到数据
    # print(request.form)
    # print(request.form['name'])
    # print(request.form.get('name'))
    # print(request.form.getlist('name'))
    # print(request.form.get('nickname', default='little apple'))

    resp_data = dict()
    resp_data["id"] = 1
    resp_data["pId"] = "1"
    resp_data["account"] = "admin"
    resp_data["status"] = 1
    resp_data["type"] = 0

    rep = {"code": 200, "msg": "ok", "data": []}
    return rep


@app.route('/api/video-gen-template/list', methods=['GET'])
def getVideo_gen_template_by_id():
    print(request.headers)
    materialType = request.args.get("materialType")
    if materialType == 1:
        resp_data = {
            "code": 200,
            "msg": "ok",
            "data": [
                {
                    "id": "14",
                    "materialType": "1",
                    "genTemplateName": "flux",
                    "genTemplate": "{\"meterial_type\":\"1\",\"backurl\":\"https://aiapi.supersale.ai/image/sd\",\"timeout\":\"120\",\"auth\":\"admin:Ai_Service_2022\",\"inputs\":[{\"lable\":\"模型类型\",\"id\":\"type\",\"desc\":\"模型类型\",\"type\":\"select\",\"value\":[{\"FLUX-schnell\":\"flux-schnell\",\"FLUX-dev\":\"flux-dev\"}],\"value_type\":\"string\",\"required\":\"true\"},{\"lable\":\"提示词\",\"desc\":\"绘画提示词\",\"id\":\"prompt\",\"type\":\"text\",\"value\":\"a dog fly in the sky\",\"value_type\":\"string\",\"required\":\"true\"},{\"lable\":\"负面提示词\",\"desc\":\"绘画负面提示词\",\"id\":\"negative_prompt\",\"type\":\"text\",\"value\":\"ugly\",\"value_type\":\"string\",\"required\":\"true\"},{\"lable\":\"宽高比\",\"desc\":\"宽高比\",\"id\":\"aspect_ratio\",\"type\":\"text\",\"value\":\"9:16\",\"value_type\":\"string\",\"required\":\"true\"},{\"lable\":\"随机率\",\"desc\":\"随机率\",\"id\":\"random_seed\",\"type\":\"slider\",\"value\":\"12:1.5:12.5\",\"value_type\":\"slider\",\"required\":\"false\"},{\"lable\":\"图片\",\"id\":\"pic_path\",\"desc\":\"本地图片\",\"type\":\"file\",\"value_type\":\"file\",\"required\":\"false\"},{\"lable\":\"是否高清\",\"desc\":\"是否高清\",\"id\":\"is_highresolution\",\"type\":\"checkbox\",\"value\":\"true\",\"value_type\":\"boolean\",\"required\":\"false\"}]}",
                    "isDeleted": 0,
                    "createTime": "2024-08-28T09:27:22.000Z",
                    "updateTime": "2024-08-28T09:27:22.000Z",
                    "tId": "1",
                    "isPublic": 1
                }
            ]
        }
        return resp_data
    else:
        return {"code": 200, "msg": "ok", "data": {"list": [], "total": 0}}


@app.route('/api/veditGetfile', methods=['POST', 'GET'])
def veditGetfile():
    file_path = '20241021_theme.mp4'
    # files = {'video': open(file_path, 'rb')}
    # 确保文件名是安全的，防止注入攻击
    # 假设文件都存储在static文件夹下
    return send_file('static/{}'.format(file_path), as_attachment=True)
    # response = Response(files,)
    print(request.headers)


@app.route('/api/ai-assistant/all', methods=['POST', 'GET'])
def aiAssistAll():
    print(request.headers)
    # print(request.stream.read()) # 不要用，否则下面的form取不到数据
    # print(request.form)
    # print(request.form['name'])
    # print(request.form.get('name'))
    # print(request.form.getlist('name'))
    # print(request.form.get('nickname', default='little apple'))

    resp_data = {
        "id": 1,
        "tId": "1",
        "name": "xiaotian",
        "knowledge": "请问你想知道什么",
        "createDate": "2024-10-10",
        "updateDate": "2024-10-10",
        "isDeleted": 1,
        "isPublic": 1,
        "type": 1,
        "firstResp": "1",
        "systemPrompt": "人才招聘",
    }
    rep = {}
    rep["code"] = 400
    rep["data"] = [resp_data]
    rep["msg"] = "登录成功"
    return rep


@app.route('/api/user/one/info', methods=['POST', 'GET'])
def apiuserinfo():
    resp_Data = {
        "code": 400,
        "msg": "ok",
        "data": {
            "id": 6552,
            "tId": "18",
            "title": "test",
            "videoTitle": "",
            "content": "",
            "code": "\"\"",
            "catalog": " : : :",
            "keywords": "",
            "coverUrl": "",
            "videoUrl": "",
            "videoChange": "",
            "videoType": "douyin",
            "videoActor": "",
            "courseId": 1,
            "courseName": "日常发布",
            "orderInCourse": 0,
            "pubStatus": "-1-问题输入",
            "pubData": "{\"isoriginal\":\"转载\"}",
            "extra": None,
            "createDate": "2024-10-22T11:07:28.000Z",
            "updateDate": "2024-10-22T11:07:28.000Z",
            "language": "zh-CN",
            "isDeleted": 0,
            "accountName": "默认数字人-小火_20241013_201430"
        }
    }
    return resp_Data


@app.route('/api/ai-assistant-chat/ai', methods=['POST'])
def aiResponse():
    print(request.headers)
    # print(request.stream.read()) # 不要用，否则下面的form取不到数据
    # print(request.form)
    # print(request.form['name'])
    # print(request.form.get('name'))
    # print(request.form.getlist('name'))
    # print(request.form.get('nickname', default='little apple'))
    rep = {}
    rep["code"] = 200
    rep["body"] = "wvNH/20uaaBpBlU7h4Foxw==adsfadfsadfsafdasfsafasf+\n + adfafdasfsdfafuhihiasgfuasgdfu"
    rep["msg"] = "登录成功"

    return rep


@app.route('/api/actor', methods=['POST', 'GET'])
def aiAct():
    print(request.headers)
    # print(request.stream.read()) # 不要用，否则下面的form取不到数据
    # print(request.form)
    # print(request.form['name'])
    # print(request.form.get('name'))
    # print(request.form.getlist('name'))
    # print(request.form.get('nickname', default='little apple'))
    rep = {
        "code": 200,
        "msg": "ok",
        "data": [
            {
                "id": 72,
                "name": "default-xiaohuo_20241013_201430",
                "accountName": "默认数字人-小火_20241013_201430",
                "createDate": "2024-10-13T12:14:30.000Z",
                "updateDate": "2024-10-13T12:14:30.000Z",
                "isDeleted": 0,
                "tId": "18",
                "imgUrl": "/default/shuixing1.png",
                "imgUrlPrefix": "https://upload-1316514432.cos.ap-singapore.myqcloud.com",
                "fullName": "default-xiaohuo_20241013_201430 默认数字人-小火_20241013_201430",
                "fullImageUrl": "https://upload-1316514432.cos.ap-singapore.myqcloud.com/default/shuixing1.png"
            }
        ]
    }

    # rep["code"] = 200
    # rep["body"] = "wvNH/20uaaBpBlU7h4Foxw==adsfadfsadfsafdasfsafasf+\n + adfafdasfsdfafuhihiasgfuasgdfu"
    # rep["msg"] = "登录成功"

    return rep


@app.route('/logout', methods=['GET'])
def logout():
    print(request.headers)
    # print(request.stream.read()) # 不要用，否则下面的form取不到数据
    # print(request.form)
    # print(request.form['name'])
    # print(request.form.get('name'))
    # print(request.form.getlist('name'))
    # print(request.form.get('nickname', default='little apple'))
    rep = {}
    rep["code"] = 200
    rep["data"] = "wvNH/20uaaBpBlU7h4Foxw=="
    rep["msg"] = "登录成功"
    return rep


@app.route('/register', methods=['POST'])
def register():
    print(request.headers)
    # print(request.stream.read()) # 不要用，否则下面的form取不到数据
    print(request.form)
    print(request.form['name'])
    print(request.form.get('name'))
    print(request.form.getlist('name'))
    print(request.form.get('nickname', default='little apple'))
    return 'welcome'


@app.route('/json2execle', methods=['POST'])
def json2execle():
    json = request.get_json()
    print(json)
    bill_no = request.args.get("bill_no")
    filename = json2excel.json_to_json(json, bill_no)
    if filename == None or filename == '': return "error"
    # resFile = {'file' :  open(filename, 'rb')}
    return send_file(filename)


# 启动服务器
if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8081)
